package com.flyme.module.base.provider.service.impl;

import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.utils.ObjectUtils;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.core.base.supper.service.impl.BaseServiceImpl;
import com.flyme.module.base.client.entity.SysKeyword;
import com.flyme.module.base.client.entity.SysWorkCourse;
import com.flyme.module.base.client.enums.WorkingYearEnum;
import com.flyme.module.base.provider.mapper.SysKeywordMapper;
import com.flyme.module.base.provider.mapper.SysWorkCourseMapper;
import com.flyme.module.base.provider.service.SysKeywordService;
import com.flyme.module.base.provider.service.SysWorkCourseService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysKeywordServiceImpl extends BaseServiceImpl<SysKeywordMapper, SysKeyword> implements SysKeywordService {


    /**
     * 保存或更新热刺
     */
    public void keyRecord(String keyword){
        SysKeyword word = getOne(q().eq("keyword", keyword));
        if(ObjectUtils.isNotEmpty(word)){
            word.setCount(word.getCount()+1);
            saveOrUpdate(word);
            return;
        }
        word = new SysKeyword();
        word.setKeyword(keyword);
        word.setCount(0);
        save(word);
        return;
    }

    /**
     * 查询热刺
     */
    public List<EntityMap> selectList(){
        PagerInfo pagerInfo = new PagerInfo();
        pagerInfo.setPageSize(5);
        pagerInfo.setPageNumber(1);
        CriteriaQuery queryWrapper = new CriteriaQuery<EntityMap>(pagerInfo);
        queryWrapper.select("keyword,count");
        queryWrapper.orderByDesc("count");
        return (List<EntityMap>) pageList(queryWrapper).getRows();
    }

}
